@extends('layouts.admin.header')
@section('cnt')
<div class="layui-fluid">
    <div class="layui-row">

        <form class="layui-form">
            @csrf
            <input type="hidden" id="id" name="id" required="" lay-verify="required"
                   autocomplete="off" class="layui-input" value="{{$data->id}}" >
            <div class="layui-form-item">
                <label class="layui-form-label">父级菜单</label>
                <div class="layui-input-block" style="width: 190px;">
                    <select name="pid" lay-verify="required" lay-filter="menutree-dropdown" >
                        <option value="0">ROOT</option>
                        @foreach($list as $k=>$v)
                            @if($v['id']==$data->pid)
                            <option selected value="{{$v['id']}}">{{$v['name']}}</option>
                                @else
                            <option value="{{$v['id']}}">{{$v['name']}}</option>
                            @endif
                        @endforeach
                    </select>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>请选择父级菜单
                    </div>
                </div>

            </div>
            <div class="layui-form-item">
                <label for="url" class="layui-form-label">
                    <span class="x-red">*</span>权限规则
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="url" name="url" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="{{$data->url}}" >
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>请输入权限规则
                </div>
            </div>
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>权限名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="{{$data->name}}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>请输入权限名称
                </div>
            </div>

            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    保存
                </button>
            </div>
        </form>

    </div>
</div>
@endsection
@section('js')
<script>
    layui.use(['form', 'layer'],
        function() {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;
            //监听提交
            form.on('submit(add)', function(data) {
                console.log(data.field);

                $.ajax({
                    type:'put',
                    url:'/admin/adminmenu/'+data.field.id,
                    data:data.field,
                    success:function(data){
                        if(data.status==200){
                            //发异步，把数据提交给php
                            layer.alert("修改成功", {
                                    icon: 6
                                },
                                function() {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                        }else{
                            //发异步，把数据提交给php
                            layer.alert("修改失败", {
                                    icon: 5
                                },
                                function() {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                        }
                    }
                })
                return false;
            });


        });
</script>
@endsection
